Skip to content

Comments

feat: bash tool execution in background#10285

Merged
sestinj merged 18 commits intocontinuedev:mainfrom
uinstinct:cli-background-bash-exec
Feb 18, 2026
Merged

feat: bash tool execution in background#10285
sestinj merged 18 commits intocontinuedev:mainfrom
uinstinct:cli-background-bash-exec

Conversation

@uinstinct
Copy link
Contributor

@uinstinct uinstinct commented Feb 6, 2026

Description

Introduces moving terminal command to run in the background

AI Code Review

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • [] I've read the contributing guide
  • [] The relevant docs, if any, have been updated or created
  • [] The relevant tests, if any, have been updated or created

Screen recording or screenshot

feat.mp4

Tests

[ What tests were added or updated to ensure the changes work as expected? ]


Continue Tasks: ▶️ 1 queued — View all


Summary by cubic

Run Bash tool commands in the background from the CLI. Press Ctrl+B to background a running command, stream foreground output, and monitor jobs via /jobs or the CheckBackgroundJob tool (background output capped at 1000 lines).

  • New Features

    • Background jobs with IDs, status, output capture, limits (max 5 concurrent, 1000-line cap), and auto-kill on exit.
    • Ctrl+B moves the current Bash execution to the background and returns the Job ID.
    • /jobs opens an interactive screen to view job details (status, duration, last output) and cancel running jobs.
    • CheckBackgroundJob tool returns a job’s status, exit code, timestamps, duration, and full output as JSON.
    • TUI shows “ctrl+b to background” while the Bash tool is running.
  • Bug Fixes

    • Fixed a circular dependency in ToolPermissionService by extracting built-in tool names; also fixed TypeScript/import ordering and Vitest module resolution with a src path alias.
    • Prevented memory growth by detaching stdout/stderr listeners after backgrounding; set UTF-8 encoding to avoid multi-byte corruption.
    • Fixed stale updates in the Jobs screen; truncate output when backgrounding to keep within output limits.

Written for commit 87a0464. Summary will update on new commits.

@uinstinct uinstinct marked this pull request as ready for review February 9, 2026 13:43
@uinstinct uinstinct requested a review from a team as a code owner February 9, 2026 13:43
@uinstinct uinstinct requested review from sestinj and removed request for a team February 9, 2026 13:43
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Feb 9, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 20 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="extensions/cli/src/ui/JobsSelector.tsx">

<violation number="1" location="extensions/cli/src/ui/JobsSelector.tsx:49">
P2: Polling effect uses a stale closure: viewMode/selectedJob aren’t in the dependency array, so the interval never sees updates and detail view auto-refresh won’t run.</violation>
</file>

<file name="extensions/cli/src/tools/runTerminalCommand.ts">

<violation number="1" location="extensions/cli/src/tools/runTerminalCommand.ts:225">
P2: After moving the process to background, stdout/stderr/data listeners are never detached, so they keep appending to captured buffers and updating chat history even though the tool call is resolved, causing memory growth and spurious updates.</violation>

<violation number="2" location="extensions/cli/src/tools/runTerminalCommand.ts:242">
P2: Backgrounding a command returns unbounded stdout without applying the existing truncation limits, which can overflow context if the process has produced large output before backgrounding.</violation>
</file>

<file name="extensions/cli/src/services/BackgroundJobService.ts">

<violation number="1" location="extensions/cli/src/services/BackgroundJobService.ts:72">
P2: Output capture decodes each Buffer chunk with toString(), which can corrupt multi‑byte characters split across chunks. Use StringDecoder or setEncoding on the streams to preserve UTF‑8 sequences across chunk boundaries.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

sestinj and others added 5 commits February 18, 2026 12:35
- Add missing import for backgroundJobService in services/index.ts
- Add explicit type annotation for BackgroundJob parameter in checkBackgroundJob.ts
- Fix stale closure in JobsSelector useEffect by adding viewMode/selectedJob to deps
- Truncate stdout when moving command to background to prevent context overflow
- Detach stdout/stderr listeners after backgrounding to prevent memory growth
- Use setEncoding('utf8') on streams to prevent multi-byte character corruption

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The tsconfig uses baseUrl: "." which allows imports like "src/..." to
resolve correctly for tsc, but vitest doesn't read tsconfig paths by
default. This adds a resolve.alias to map "src" to the actual source
directory so tests can resolve these imports.

Fixes ToolPermissionService test failures (TypeError: ToolPermissionService
is not a constructor) caused by failed module resolution of "src/..." paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ToolPermissionService imported ALL_BUILT_IN_TOOLS from allBuiltIns.ts,
which imports runTerminalCommand.ts, which imports services/index.ts,
which imports ToolPermissionService.ts - creating a circular dependency.

This caused "ToolPermissionService is not a constructor" errors in tests
because the module wasn't fully initialized when services/index.ts tried
to instantiate it.

Fix: Extract a lightweight builtInToolNames.ts with just the string names
(no heavy imports) and use that in ToolPermissionService instead. Also add
a vitest resolve alias for "src/" paths to match tsconfig baseUrl.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Feb 18, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 18, 2026
@sestinj
Copy link
Contributor

sestinj commented Feb 18, 2026

awesome work! i think all that stuff was failing on the main branch too but i just went ahead and cleaned it up here

@sestinj sestinj merged commit c1f9518 into continuedev:main Feb 18, 2026
51 of 52 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Issues and PRs Feb 18, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Feb 18, 2026
@uinstinct uinstinct deleted the cli-background-bash-exec branch February 19, 2026 04:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants